<template>
  <el-container>
    <el-header>
      <span>快吧商城后台系统</span>
      <el-button type="primary" size="mini" @click="back">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">zoom</div>
        <el-menu default-active="home" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b"
          :unique-opened="true" :collapse="isCollapse" :collapse-transition="false" router>
          <el-submenu :index="item.id+''" v-for="item in menusList" :key="item.id">
            <template slot="title">
              <i :class="iconsObj[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item :index="'/'+item1.path" v-for="item1 in item.children" :key="item1.id">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{item1.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data () {
    return {
      router: true,
      menusList: '',
      iconsObj: {
        125: 'iconfont icon-user',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao'
      },
      isCollapse: false,
      path: 1
    }
  },
  mounted () {
    this.getMenus()
  },
  methods: {
    async getMenus () {
      const {
        data: res
      } = await this.$http.get('http://kb.dekunlu.top/api/private/v1/menus')
      if (res.meta.status === 400) {
        return this.$message.error('获取数据失败')
      }
      this.menusList = res.data
    },
    back () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    toggleCollapse () {
      this.isCollapse = !this.isCollapse
    }
  }
}
</script>

<style lang="less" scoped>
  .el-container {
    height: 100%;
    // background: url('../assets/img/bg.png') no-repeat 100% 100%;
    background-color: #565c68;
    background-size: 100%;
  }

  .el-menu {
    border: none;
  }

  .el-header {
    //background-color: #333;
    //background: url('../assets/img/bg.png') no-repeat;
    color: white;
    line-height: 60px;

    span {
      font-size: 20px;
    }

    .el-button {
      float: right;
      margin-top: 17px;
    }
  }

  .el-aside {
    //background-color: #888;
    //background: url('../assets/img/bg.png') no-repeat;

    .toggle-button {
      width: 100%;
      height: 30px;
      color: white;
      line-height: 30px;
      text-align: center;
      background: #545c69;
      //background: url('../assets/img/bg.png') no-repeat;
    }
    ::before {
      margin-right: 15px;
    }
  }

  .el-main {
    background-color: #E9EEF3;
    //background: url('../assets/img/bg.png') no-repeat 42% 5%;
    color: #333;
  }
</style>
